// ==UserScript==
// @name         KityMind - ShortCut
// @namespace    http://tampermonkey.net/
// @version      0.2.1
// @description  增加快捷键
// @author       brt2
// @match        https://naotu.baidu.com/file/*
// @icon         https://naotu.baidu.com/favicon.ico
// @grant        none
// ==/UserScript==

(function() {
    $(function() {
        $(document).keydown(function (event) {
            const keyname = event.key.toLocaleLowerCase();
            // console.log(">>>", event.keyCode, keyname)
            if (event.ctrlKey && keyname == 's') {  // event.altKey
                save_as("mkm")
            // } else if (event.altKey && keyname == "h") {
            //     window.save_as("km")
            // } else if (event.altKey && keyname == 'm') {
            //     window.save_as("md")
            } else if (event.ctrlKey && keyname == "g") {
                if (!editor.commandDisabled){
                    if ($(".km-progress-item.active").length > 0){
                        editor.minder.execCommand('progress', 0)
                    } else {
                        editor.minder.execCommand('progress', 9)
                    }
                }
            // } else if (event.keyCode == 113) {  // F2
            //     $(".km-btn-item.edit-node").click()
            //     return false;
            } else if (event.altKey && keyname == "g") {
                editor.minder.execCommand('background', "#BFBFBF")  // gray
            } else if (event.ctrlKey && keyname == "d") {
                editor.minder.execCommand('background', "#FFC000")  // bright
            } else if (event.ctrlKey && keyname == "p") {
                editor.minder.execCommand('background', "#FFC7CE")  // pink
                // editor.minder.execCommand('background', "#C6F9CE")  // green
                // editor.minder.execCommand('background', "#FFEB9C")  // yellow
            } else if (event.ctrlKey && keyname == "l") {  // for linkTo
                editor.minder.execCommand('bold')
                editor.minder.execCommand('forecolor', "#FFFFFF")
                editor.minder.execCommand('background', "#7030A0")  // purple
            } else if (event.altKey && keyname == "l") {  // for linkTo curr_mkm
                editor.minder.execCommand('bold')
                editor.minder.execCommand('forecolor', "#7030a0")
                editor.minder.execCommand('background', "#eeece1")
            } else if (event.altKey && keyname == "p") {
                // $(".colorpicker-clear").click()
                editor.minder.execCommand('clearstyle')
            } else if (event.ctrlKey && keyname == "r") {
                $("button.hyperlink").click()
            } else if (event.altKey && (keyname == "r" || keyname == "a")) {
                editor.minder.execCommand('HyperLink', null)
            } else if (event.ctrlKey && keyname == "h") {
                if ($(".km-note.ng-hide").length > 0) {
                    $("button.note-btn").click()
                } else {
                    $(".glyphicon-remove").click()
                }
            } else if (event.altKey && keyname == "h") {
                editor.minder.execCommand('note', null)
            } else if (event.ctrlKey && keyname == "m") {
                $("button.image-btn").click()
            } else if (event.altKey && keyname == "m") {
                minder.execCommand('Image', null)
            } else if (event.ctrlKey && event.keyCode == 8) {  // "backspace"
                editor.history.hasUndo() == false || editor.history.undo()
            } else if (event.keyCode == 33) {
                editor.minder.queryCommandState('ArrangeUp') == -1 || editor.minder.execCommand('ArrangeUp')
            } else if (event.keyCode == 34) {
                editor.minder.queryCommandState('ArrangeDown') == -1 || editor.minder.execCommand('ArrangeDown');
            } else {
                return true;
            }
            return false;
        })
    })
})();
